package com.krubi.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "permisos")
public class Permiso 
{
	@Id
	@Column(name="id", unique=true, nullable=false )
	@GeneratedValue( strategy = IDENTITY )
	private long id;
	
	@Column(name="permiso", unique=true, nullable=false )
	private String permiso;
	
	@ManyToMany(targetEntity=Permiso.class,
			cascade={CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="permisos_x_roles",
			joinColumns=@JoinColumn(name="id_permiso"),
			inverseJoinColumns=@JoinColumn(name="id_rol"))
	private List<Rol> roles;
	
	public long getId() 
	{
		return id;
	}

	public void setId(long pId) 
	{
		id = pId;
	}

	public String getPermiso() 
	{
		return permiso;
	}

	public void setPermiso(String pPermiso)
	{
		permiso = pPermiso;
	}

	public List<Rol> getRoles() 
	{
		return roles;
	}

	public void setRoles(List<Rol> pRoles) 
	{
		roles = pRoles;
	}	
	
}
